package 剑指offer;

import 链表.ListNode;

import java.util.ArrayList;

public class _06从未到头打印链表 {
    ArrayList<Integer> temp = new ArrayList<Integer>();
    public int[] reversePrint(ListNode head) {
        reversePrintHelper(head);
        int[] result = new int[temp.size()];
        for(int i = 0; i < temp.size(); i++) {
            result[i] = temp.get(i);
        }
        return result;
    }
    public void reversePrintHelper(ListNode head) {
        if(head == null) {
            return;
        }
        reversePrintHelper(head.next);
        temp.add(head.val);
    }
}
